/*
 * @Author: wankong
 * @Date: 2021-09-20 11:58:33
 * @LastEditTime: 2021-12-24 15:53:27
 */
import Vue from 'vue'

import axios from 'axios'
const baseURL = "spring.wankong.top"

// const baseURL = "localhost:9090"
axios.defaults.baseURL = "http://" + baseURL + "/"
const adminPre = "mmht";
const userPre = "api";

// 配置拦截请求
axios.interceptors.request.use(config => {
    /**
     * 判断是用户端 还是后台发起的请求
     * 如果是后台发起的，则添加验证信息
     * 否则添加前缀  userPre / 
     */
    const urls = config.url.split("/");
    if (urls[0] == adminPre) {
        config.headers.Authorization = window.sessionStorage.getItem('Authorization');
        return config;
    } else {
        config.url = userPre + "/" + config.url;
        return config
    }
})

axios.interceptors.response.use((response) => {
    if (response.data.code === "504") {
        alert("登录已失效，请重新登录")
    } else if (response.data.code == 504) {
        alert("登录已失效，请重新登录")
    }
    return response.data;
})

Vue.prototype.adminPre = adminPre;
Vue.prototype.$http = axios
Vue.prototype.BaseUrl = baseURL